package demo2;

import java.util.Arrays;

class Student implements Comparable<Student>
{
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }


    @Override
    public int compareTo(Student o) {
//        //从大到小
//        if(this.score>o.score)
//        {
//            return -1;
//        }else if(this.score<o.score)
//        {
//            return 1;
//        }
//        else
//        {
//            return 0;
//        }


//        //从小到大
//        if(this.age>o.age)
//        {
//            return 1;
//        }else if(this.age<o.age)
//        {
//            return -1;
//        }
//        else
//        {
//            return 0;
//        }


        if(this.name.compareTo(o.name)>0)
        {
            return -1;
        }
        else if(this.name.compareTo(o.name)<0)
        {
            return 1;
        }
        else
        {
            return  0;
        }
    }
}
public class Test {
    public static void main(String[] args) {
        Student[] students=new Student[3];
        students[0]=new Student("zhangsan",10,10);
        students[1]=new Student("lisi",20,20);
        students[2]=new Student("wangwu",30,30);

        //System.out.println(students[0].compareTo(students[1]));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
}
